// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: base.cpp 318 2009-03-02 14:03:21Z heavyzheng $
//

#ifndef ZZHENG_XML_SOURCE
#define ZZHENG_XML_SOURCE
#endif // ZZHENG_XML_SOURCE

#include <zzheng/xml/dom/libxml2/base.hpp>
#include <zzheng/xml/dom/libxml2/callbacks.hpp>
#include <zzheng/xml/dom/exception.hpp>

#include <libxml/tree.h>
#include <cassert>

namespace zzheng {
namespace xml {
namespace dom {
namespace libxml2_ {

    globals::globals() {
        LIBXML_TEST_VERSION;  // check libxml2 version.
        xmlInitParser();      // initialize parser (necessary for thread safety).
        register_callbacks(); // Register libxml2 callback functions.
        xmlSubstituteEntitiesDefault(1);
        xmlLoadExtDtdDefaultValue = 1;
    }

    globals::~globals() {
        try {
            // xsltCleanupGlobals();
            xmlCleanupParser();
        } catch (...) {
            // ignore all errors to make destructor exception-free.
        }
    }

    base::base() {
        // Call the instance function to make sure the globals singleton instance is created.
        // We don't need the singleton instance, so we don't care about the return value.
        globals::instance();
    }

} // namespace zzheng::xml::dom::libxml2_
} // namespace zzheng::xml::dom
} // namespace zzheng::xml
} // namespace zzheng



